<template>
	<view class="page page-cash">
		<!-- 头部 -->
		<view class="balance flex-row-between">
			<view class="font15">账户剩余金额：<text class="font-assist">{{info.money}}</text>元</view>
			<view class="font-link font13" @click="Onall">全部提现</view>
		</view>
		<!-- 输入金额 -->
		<view class="amount flex-row-start">
			<view class="font20 font-b">￥</view>
			<input type="digit" @input="Oninput" data-type="coin" :value="coin" placeholder="请输入提现金额" placeholder-class="placeholderClass" />
		</view>
		<!-- T提示 -->
		<view class="tips">*每月可提现1次(仅限28-31号)，次月15号前到账</view>
		<view class="hr7"></view>
		<!-- 表单 -->
		<!-- <view class="item">
			<view class="label">提现方式</view>
			<image class="icon1" src="https://static.newbeaconhotels.com/app/hotel/coin/true.png"></image>
			<image class="icon2" src="https://static.newbeaconhotels.com/app/hotel/coin/alipay.png"></image>
			<view>支付宝</view>
		</view>
		<view class="item">
			<view class="label">姓名<text>*</text></view>
			<input @input="Oninput" data-type="alipay_name" :value="alipay_name" placeholder="请输入您的姓名" placeholder-class="placeholderClass" />
		</view>
		<view class="item">
			<view class="label">账号<text>*</text></view>
			<input @input="Oninput" data-type="alipay_account" :value="alipay_account" placeholder="请输入您的支付宝账号" placeholder-class="placeholderClass" />
		</view>
		<view class="item">
			<view class="label">身份证<text>*</text></view>
			<input @input="Oninput" data-type="alipay_idcard" :value="alipay_idcard" placeholder="请输入您的身份证号码" placeholder-class="placeholderClass" />
		</view> -->
		<!-- 按钮 -->
		<view class="fix-bottom-btn flex-row-center">
			<view class="btn flex-row-center font-ffffff font15" @click="Onapply">提交申请</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info: {}, //用户信息
				alipay_name: '', //支付宝用户名
				alipay_idcard: '', //身份证号
				alipay_account: '', //支付宝账号
				coin: 0, //提现纽扣币金额
			}
		},
		onLoad() {
			this.$Http({
				url: 'tixian',
				token: true,
				load: true
			}).then(res => {
				if (res.code == 1) {
					this.info = res.data
					this.alipay_name = res.data.alipay_name ? res.data.alipay_name : ''
					this.alipay_idcard = res.data.alipay_idcard ? res.data.alipay_idcard : ''
					this.alipay_account = res.data.alipay_account ? res.data.alipay_account : ''
				}
			});
		},
		methods: {
			Oninput(e) {
				let dataset = e.currentTarget.dataset
				//金额
				if (dataset.type == 'coin') {
					this.coin = e.detail.value
				}
				//如果是姓名
				if (dataset.type == 'alipay_name') {
					this.alipay_name = e.detail.value
				}
				//如果是身份证号
				if (dataset.type == 'alipay_idcard') {
					this.alipay_idcard = e.detail.value
				}
				//如果是支付宝账号
				if (dataset.type == 'alipay_account') {
					this.alipay_account = e.detail.value
				}
			},
			//体现
			Onapply() {
				if (this.coin == '' || this.coin == 0) {
					uni.showToast({ icon: 'none', title: '请输入提现金额' });
					return
				}
				if (this.coin > this.info.money * 100 / 100) {
					uni.showToast({ icon: 'none', title: '提现金额不能超过账号余额' });
					return
				}
				// if (this.alipay_name == '') {
				// 	uni.showToast({ icon: 'none', title: '请输入姓名' });
				// 	return
				// }
				// if (this.alipay_account == '') {
				// 	uni.showToast({ icon: 'none', title: '请输入支付宝账号' });
				// 	return
				// }
				// if (!this.$base.checkCard(this.alipay_idcard)) {
				// 	uni.showToast({ icon: 'none', title: '身份证格式不正确' });
				// 	return
				// }
				let data = {
					money: this.coin,
					alipay_name: this.alipay_name,
					alipay_idcard: this.alipay_idcard,
					alipay_account: this.alipay_account,
				}
				this.$Http({
					url: 'tixian',
					data: data,
					token: true,
					load: true,
					type: 'POST'
				}).then(res => {
					if (res.code == 1) {
						uni.showToast({ title: '申请成功~' });
						this.coin = 0
						setTimeout(()=>{
							uni.reLaunch({
								url: '/pages/coin/detailed'
							})
						}, 2000)
					} else {
						uni.showToast({ title: res.msg, icon: 'none' });
					}
				});
			},
			// 全部体现
			Onall() {
				this.coin = this.info.money * 100 / 100
			},
		}
	}
</script>

<style lang="less">
	@import url("style.less");
</style>
